package com.gp.controller;

import com.github.pagehelper.PageInfo;
import com.gp.entity.Role;
import com.gp.service.RoleService;
import com.gp.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 来一杯凉咖
 * @create 2022/3/11 9:05
 */
@RestController
@RequestMapping("/system")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/findAllRole")
    public PageInfo<Role> findAllRole(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "10")Integer size){
        PageInfo<Role> page1 = roleService.getAllRoleForPage(page, size);
        return page1;
    }
    @PostMapping("/editRole")
    public CommonResult editRole(@RequestBody  Role role){
        return roleService.editRole(role);
    }
    @GetMapping("/delRole")
    public CommonResult delRole(Integer roleId){
        return roleService.deleteRoleById(roleId);
    }

    @GetMapping("/selectRole")
    public PageInfo<Role> selectRole(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "10")Integer size,String roleName,String createBy){
        PageInfo<Role> rolePageInfo = roleService.queryRole(page, size, roleName, createBy);
        return  rolePageInfo;
    }


}
